package com.sinoeyes.controller.compent;

import com.sinoeyes.common.constant.Constants;
import com.sinoeyes.common.core.controller.BaseController;
import com.sinoeyes.common.result.R;
import com.sinoeyes.common.utils.bean.ObjectUtils;
import com.sinoeyes.compent.po.DimensionInfo;
import com.sinoeyes.compent.service.IDimensionInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 维度管理接口
 *
 * @author aries.hao
 */
@Api(value = "Dimension API", tags = {"维度管理接口"})
@RestController
@RequestMapping("/dimension")
public class IDimensionController extends BaseController {

    private final IDimensionInfoService dimensionInfoService;

    @Autowired
    public IDimensionController(IDimensionInfoService dimensionInfoService) {
        this.dimensionInfoService = dimensionInfoService;
    }

    @ApiOperation("获取单条维度信息")
    @ApiImplicitParam(name = "dimensionId", value = "维度ID", required = true, dataType = "String", paramType = "path")
    @GetMapping("/getDimensionInfoById/{dimensionId}")
    public String getDimensionInfoById(@PathVariable String dimensionId) {
        DimensionInfo dimensionInfo = dimensionInfoService.selectDimensionInfoById(dimensionId);
        if (ObjectUtils.isNotEmpty(dimensionInfo)) {
            return convertJsonWithDate(R.success(dimensionInfo));
        }
        return jsonResult(R.failure("未获取到维度相关信息"));
    }

    @ApiOperation("条件获取维度信息")
    @PostMapping("/getDimensionByFilter")
    public String getDimensionByFilter(@RequestBody(required = false) DimensionInfo dimensionInfo) {
//        startPage();
//        List<DimensionInfo> dimensionList = dimensionInfoService.selectDimensionInfoList(dimensionInfo);
//        if (!CollectionUtils.isEmpty(dimensionList)) {
//            return convertJsonWithDate(R.success(getRestTable(dimensionList)));
//        }
        return jsonResult(R.failure("未获取到维度信息！"));
    }

    @ApiOperation("添加维度信息")
    @PostMapping(value = "/addDimension")
    public String addDimension(@RequestBody DimensionInfo dimensionInfo) {
        int i = dimensionInfoService.insertDimensionInfo(dimensionInfo);
        if (i > 0) {
            return jsonResult(R.success("维度信息添加成功"));
        }
        return jsonResult(R.failure("维度信息添加失败"));
    }

    @ApiOperation("更新维度")
    @ApiImplicitParam(name = "dimensionInfo", value = "修改维度信息", dataType = "DimensionInfo")
    @PostMapping("/updateDimension")
    public String updateDimension(@RequestBody DimensionInfo dimensionInfo) {
        int i = dimensionInfoService.updateDimensionInfo(dimensionInfo);
        if (i > 0) {
            return jsonResult(R.success("维度信息修改成功"));
        }
        return jsonResult(R.failure("维度信息修改失败"));
    }

    @ApiOperation("删除维度信息")
    @ApiImplicitParam(name = "dimensionId", value = "维度ID", required = true, dataType = "String", paramType = "path")
    @DeleteMapping("/deleteDimension/{dimensionId}")
    public String deleteDimension(@PathVariable String dimensionId) {
        int i = dimensionInfoService.deleteDimensionInfoById(dimensionId, Constants.DEL_FLAG);
        if (i > 0) {
            return jsonResult(R.success("维度信息删除成功"));
        }
        return jsonResult(R.failure("维度信息删除失败"));
    }

    @ApiOperation("启用维度信息")
    @ApiImplicitParam(name = "dimensionId", value = "维度ID", required = true, dataType = "String", paramType = "path")
    @PutMapping("/enableDimension/{dimensionId}")
    public String enableDimension(@PathVariable String dimensionId) {
        int i = dimensionInfoService.deleteDimensionInfoById(dimensionId, Constants.ENABlE_FLAG);
        if (i > 0) {
            return jsonResult(R.success("维度信息启用成功"));
        }
        return jsonResult(R.failure("维度信息启用失败"));
    }


}
